var url = null;

/**
 * 增加网点
 */
function initAdd() {
	url = getHttpRequestPath("system/addBranch");
	clearData();

	$('#dlg').dialog({
		modal : true
	}).dialog('open').dialog('setTitle', '增加网点');
}

/**
 * 修改网点
 */
function initEdit(branchId) {
	url = getHttpRequestPath("system/editBranch");
	clearData();
	getBranch(branchId);
	$('#branchId_text').attr("disabled", true);
	$('#dlg').dialog({
		modal : true
	}).dialog('open').dialog('setTitle', '修改网点');
}

/**
 * 查询
 */
function query() {
	var cmd = new Cmd();
	var branchName = $("#branchName_query").val();
	cmd.branchName = branchName.length > 0 ? branchName : null;
	
	$('#dg').datagrid({
		url : getHttpRequestPath("system/queryBranchsList"),
		pageNumber : 1,
		queryParams : {
			cmd : JSON.stringify(cmd, cmd.StringifyReplacer)
		}
	});
}

function clearData() {
	$('#branchId_text').val("");
	$('#branchId_text').attr("disabled", false);
	$("#branchName_text").val("");
}

/**
 * 初始化表单数据
 * 
 * @param row
 */
function initBranch(branch) {
	$("#branchId_text").val(branch.branchId);
	$("#branchName_text").val(branch.branchName);
}

var formatDateStr = "yyyy-MM-dd hh:mm:ss";
function formatDate(val, row, index) {
	var str ="";
	str += new Date(row.registDate).format(formatDateStr);
	return str;
}

/*
 * 操作
 */
function formatAction(val, row, index) {
	var str = ""; 
	str += createLinkElement('编辑', 'initEdit(\'' + row.branchId + '\')', 'icon-edit');
	str += createLinkElement('删除', 'delBranch(\'' + row.branchId + '\')', 'icon-cancel');
	return str;
}